/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.componentes;

import com.mapping.Componentes;
import com.mapping.TipoDisp;
import com.opensymphony.xwork2.ActionSupport;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value = "/")
@Action(value = "altaComponente2", results = {@Result(name = "success", location = "/GestionComponentes/rAltaComponente.jsp")})
public class AltaComponenteAction extends ActionSupport{
    private String tipo;
    private String caracteristicas;
    private String estatus;
    private String cantidad;
    @Override
    public String execute(){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        for(int i=Integer.parseInt(cantidad);i>0;i--){
            Componentes comp = new Componentes();
            comp.setIdTipo((TipoDisp) em.getReference(TipoDisp.class, Integer.parseInt(tipo)));
            comp.setCaracteristicas(caracteristicas);
            comp.setStatus(estatus);
            em.persist(comp);
        }
        em.flush();
        tx.commit();
        em.close();
        return SUCCESS;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public void setCaracteristicas(String caracteristicas) {
        this.caracteristicas = caracteristicas;
    }

    public void setEstatus(String estatus) {
        this.estatus = estatus;
    }

    public void setCantidad(String cantidad) {
        this.cantidad = cantidad;
    }
    
}
